package com.gitee.jisong.kit;

import java.util.Collection;
import java.util.Map;

/**
 * @author sunjisong 2019-07-16
 */
public class Kit {

    private Kit(){}

    public static boolean isEmpty(Object o){
        if(null == o){
            return true;
        }
        if(o instanceof Collection){
            return ((Collection) o).isEmpty();
        }
        if(o instanceof Map){
            return ((Map) o).isEmpty();
        }
        if(o instanceof String){
            String str = (String) o;
            return str.trim().length() == 0 || "null".equals(str.toLowerCase());
        }
        return false;
    }
    public static boolean isEmpty(Object[] ao){
        return null == ao || ao.length <= 0;
    }


    public static int size(Collection c){
        if(c == null) return 0;
        return c.size();
    }

    public static int size(Map m){
        if(null == m) return 0;
        return m.size();
    }

    public static int size(Object[] ao){
        if(ao == null) return 0;
        return ao.length;
    }

    public static <T> T def(T t,T def){
        return null == t? def:t;
    }

}
